package demo2;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "MyFilter",urlPatterns = "/login")
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }
    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain)
            throws IOException, ServletException {
        servletResponse.setContentType("text/html;charset=UTF-8");
        String username = servletRequest.getParameter("username");
        String password = servletRequest.getParameter("password");
        //servletResponse.getWriter().write("第一级过滤-MyFilter");
        //servletResponse.getWriter().write(username);
        //filterChain.doFilter(servletRequest,servletResponse);

        if(password.length()>=8){
            filterChain.doFilter(servletRequest,servletResponse);
        }else {
            servletResponse.getWriter().write("密码设定不符合要求--密码长度小于8");
        }
    }

    @Override
    public void destroy() {

    }

}